home *** CD-ROM | disk | FTP | other *** search
/ Ray Dream Studio 5 / Ray Dream.iso / pc / DreamSDK / Windows / INCLUDES / 3DCOFAIL.H < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-11  |  4.5 KB  |  143 lines

  1. /* $Id: 3DCOFAIL.H 1.11 1997/04/14 23:20:37 TOM Exp $ */
  2. /*****************************************************************************\
  3. *                                                                             *
  4. * 3DCoFail.h                                                                                *
  5. *           Failure handling for COM extensions                               *
  6. *                                                                             *
  7. *           Copyright (c) 1995, Ray Dream, Inc. All rights reserved.          *
  8. *                                                                             *
  9. \*****************************************************************************/
  10.  
  11. #ifndef __3DCOFAIL__
  12. #define __3DCOFAIL__
  13.  
  14. struct IShUtilities;
  15. struct IShActionManager;
  16. struct IShMenuManager;
  17. struct IShViewManager;
  18. struct IShSMPUtilities;
  19.  
  20. /*****************************************************************************\
  21. *                                                                             *
  22. *   Utilities pointers                                                        *
  23. *                                                                             *
  24. \*****************************************************************************/
  25. // gShellUtilities keeps a pointer on the Shell Utilities interface as given by
  26. // I3DExtension::ShellUtilitiesInit(). This is used as a convenient back-door
  27. // to the Shell. gShellUtilities is NULL by default, and is initialized by
  28. // InitCoFailure() (this is pretty much all what InitCoFailure() does). 
  29. extern IShUtilities*            gShellUtilities;
  30. extern IShActionManager*    gActionManager;
  31. extern IShMenuManager*        gMenuManager;
  32. extern IShViewManager*        gViewManager;
  33. extern IShSMPUtilities*        gShellSMPUtilities;
  34.  
  35. /*****************************************************************************\
  36. *                                                                             *
  37. *   Failure Handling                                                          *
  38. *                                                                             *
  39. \*****************************************************************************/
  40. // Initialize gShellUtilities. Must be called to have working failure handling
  41. void InitCoFailure(IShUtilities* shellUtilities);
  42.  
  43. // Failure handling
  44. #ifdef qPowerPC
  45. typedef int jmp_buf[64];
  46. #else
  47. typedef int jmp_buf[16];
  48. #endif
  49.  
  50. #ifdef __cplusplus
  51. extern "C" {
  52. #endif
  53.  
  54. #if defined(_MAC) && !defined(_MSMAC)
  55. #define __cdecl
  56. #endif
  57.  
  58. void FailNIL(void* apointer);
  59. void FailOSErr(short err);
  60.  
  61. #ifdef __cplusplus
  62. }
  63. #endif
  64.  
  65. #ifdef __cplusplus
  66.  
  67. #define VOLATILE(a) ((void)&a)
  68. #define DECLAREVOLATILE(a,b) a volatile b;
  69.  
  70. class FailInfo {
  71. public:
  72.     jmp_buf savedState;
  73.     short error;
  74.     long message;
  75.     FailInfo* nextInfo;
  76. public:
  77.     FailInfo();
  78.     inline void ReSignal();
  79.     inline void Success();
  80.     inline void Reset();
  81.   inline short GetError();
  82.   inline long GetMessage();
  83.     };
  84. typedef FailInfo* FailInfoPtr;
  85.  
  86. void __cdecl Failure(short error, long message);
  87.  
  88. extern "C" {
  89. FailInfoPtr* __cdecl GetGTopHandler();
  90. typedef int (*RDsetjmpProc)(jmp_buf);
  91. extern RDsetjmpProc RDsetjmp;
  92. }
  93.  
  94.  
  95. //----------------------------------------------------------------------------------------
  96. // FailInfo inline method definitions
  97. //----------------------------------------------------------------------------------------
  98.  
  99. #define TRY(f)    \
  100.     f.nextInfo = *GetGTopHandler(),                    \
  101.     (f.nextInfo ? (*GetGTopHandler() = &f, ((*RDsetjmp)(f.savedState)==0)) : 1)
  102.  
  103. inline void FailInfo::Reset() {
  104.     error = 0;
  105.     message = 0;
  106.     nextInfo = 0;
  107.     }
  108.  
  109. inline FailInfo::FailInfo() {
  110.     }
  111.  
  112. inline void FailInfo::ReSignal() {
  113.     ::Failure(error, message);
  114.     }
  115.  
  116. inline void FailInfo::Success() {
  117.     *GetGTopHandler() = nextInfo;
  118.     }
  119.  
  120. inline short FailInfo::GetError() {
  121.   return error;
  122.   }
  123.  
  124. inline long FailInfo::GetMessage() {
  125.   return message;
  126.   }
  127.     
  128. #endif     /* __cplusplus */
  129.  
  130. /*****************************************************************************\
  131. *                                                                             *
  132. *   Memory management                                                         *
  133. *                                                                             *
  134. \*****************************************************************************/
  135.  
  136. void* RDmalloc(unsigned long  size);
  137. void* RDcalloc(unsigned long nmemb, unsigned long size);
  138. void* RDrealloc(void* ptr, unsigned long  size);
  139. void RDfree(void* ptr);
  140.  
  141. #endif
  142.  
  143.